import random
from ascript.android.node import Selector
from ascript.android import action

from .utils import timeSleep, clickGuangGao, closeAdvertisingOnce


# 开箱得金币
def kaiXiangJinBi(itm):
    action.click(x=itm.center_x, y=itm.center_y, dur=random.randint(20, 500))
    for itm in range(10):
        # 等待时间
        timeSleep()
        # 点击广告
        print('开箱得金币=================点击广告' + str(itm))
        clickGuangGao()
        # 关闭广告
        print('开箱得金币=================点击关闭广告')
        closeAdvertisingOnce()
        timeSleep()
        fuli = Selector().id("com.phoenix.read:id/acv").find()
        if fuli:
            print('退出返回主页')
            return
